/*
 * @FilePath: /wkw/vite.config.ts
 * 介绍:配置汇总文件
 */
import { defineConfig, loadEnv, ConfigEnv } from "vite";
import viteDevConfig from "./vite.dev.config";
import viteProdConfig from "./vite.prod.config";
import viteBaseConfig from "./vite.base.config";
import viteTestConfig from "./vite.test.config";

const envResolver = {
  /**生产环境 */
  production: (v: ConfigEnv) => ({
    ...viteBaseConfig(v),
    ...viteProdConfig(v),
  }),
  /**开发环境 */
  development: (v: ConfigEnv) => ({
    ...viteBaseConfig(v),
    ...viteDevConfig(v),
  }),
  /**测试环境 */
  test: (v: ConfigEnv) => ({ ...viteBaseConfig(v), ...viteTestConfig(v) }),
};

export default defineConfig((config) => {
  const env = loadEnv(config.mode, process.cwd(), "VITE_");
  return {
    ...envResolver[config.mode](config),
  };
});
